package com.android.kotlincoroutinemvvmdemo.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.util.AttributeSet
import com.android.kotlincoroutinemvvmdemo.R

/*
* ShutdownView
* */
class ShutdownView @JvmOverloads constructor(
    context: Context,
    attributeSet: AttributeSet? = null
) : BaseView(context, attributeSet) {

    private val mStrokeWidth = context.resources.getDimension(R.dimen.dp_2)

    private val mPaint0 by lazy {
        Paint().apply {
            isAntiAlias = true
            isDither = true
            strokeCap = Paint.Cap.ROUND
            strokeWidth = mStrokeWidth
            style = Paint.Style.STROKE
            color = context.resources.getColor(R.color.color_6517E4)
        }
    }

    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
        setBackgroundColor(context.resources.getColor(R.color.color_F3F3F3))
        canvas?.apply {
            val cx = mWidth.toFloat() / 2
            val cy = mHeight.toFloat() / 2
            translate(cx, cy)

            val baseX = cx * 2 / 3
            val baseY = cy * 2 / 3
            drawArc(
                -baseX,
                -baseY,
                baseX,
                baseY,
                -80F,
                340F,
                false,
                mPaint0
            )

            drawLine(
                0F,
                -cy * 5 / 6,
                0F,
                -cy / 3,
                mPaint0
            )
        }
    }
}